<?php
error_reporting(E_ERROR | E_PARSE);
// 初始化结果变量
$result = '';

// 处理表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // 获取用户选择
    $userChoice = $_POST["choice"];

    // 电脑随机选择
    $choices = array("石头", "剪刀", "布");
    $computerChoice = $choices[array_rand($choices)];

    // 判断胜负
    if ($userChoice == $computerChoice) {
        $result = "平局！你和电脑都出了 $userChoice。";
    } elseif (
        ($userChoice == "石头" && $computerChoice == "剪刀") ||
        ($userChoice == "剪刀" && $computerChoice == "布") ||
        ($userChoice == "布" && $computerChoice == "石头")
    ) {
        $result = "你赢了！你出了". $userChoice."电脑出了". $computerChoice;
    } else {
        $result = "你输了！你出了". $userChoice."电脑出了". $computerChoice;
    }
}
?>

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜拳游戏</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <h1>猜拳游戏</h1>
    <form method="post">
        <label for="choice">请选择：</label>
        <select name="choice" id="choice">
            <option value="石头">石头</option>
            <option value="剪刀">剪刀</option>
            <option value="布">布</option>
        </select>
        <input type="submit" value="出招">
    </form>
    <?php if ($result): ?>
        <div id="result">
            <p><?php echo $result; ?></p>
        </div>
    <?php endif; ?>
</body>

</html>